package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.Product;
import cn.wolfcode.trip.base.query.ProductQueryObject;
import cn.wolfcode.trip.base.service.IProductService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("shop")
@RestController
public class ShoppingMallController {
    @Autowired
    private IProductService productService;

    /**
     * 根据分类查询商品列表
     * @param qo
     * @return
     */
    @GetMapping("/{status}")
    public PageInfo queryProductByStatus(ProductQueryObject qo){
        return productService.queryProductByStatus(qo);
    }

    /**
     * 查询最新的五条商品
     * @param qo
     * @return
     */
    @GetMapping("/news")
    public PageInfo queryProductByCreateTime(ProductQueryObject qo){
        qo.setOrderBy("create_time desc");
        return productService.queryProductByCreateTime(qo);
    }

    /**
     * 查询单个商品
     * @param id
     * @return
     */
    @GetMapping("/{id}/product")
    public Product getProductById(@PathVariable Long id){
        return productService.getProductById(id);
    }

}
